package com.baselibrary.view.mediascontentview;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.baselibrary.R;
import com.baselibrary.utils.GlideUtils;


/**
 * @author:hanke 2022/9/20
 * desc:
 */
public class MediaView extends RelativeLayout {
    private ImageView cover;
    private ImageView play;

    public MediaView(Context context) {
        super(context);
        initView();
    }

    public MediaView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public MediaView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    public MediaView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        initView();
    }

    private void initView() {
        View inflate = LayoutInflater.from(getContext()).inflate(R.layout.layout_media_view, this);
        cover = inflate.findViewById(R.id.iv_cover);
        play = inflate.findViewById(R.id.iv_play);
    }

    public void setType(int type) {
        if (type == 0) {
            play.setVisibility(View.INVISIBLE);
        } else {
            play.setVisibility(View.VISIBLE);
        }
    }

    public void setImage(Context context, String url) {
        GlideUtils.loadImg_228(context, url, cover);
    }

    public Drawable getDrawable() {
        return cover.getDrawable();
    }

    public void setImageDrawable(Drawable drawable){
        cover.setImageDrawable(drawable);
    }
}
